package com.yz.lzq.liwushuo.ui.modules.gift.tuijian;

import android.content.Context;
import android.util.Log;

import com.yz.lzq.liwushuo.jsonbean.gift.GiftTuiJianBean;

import java.util.List;

/**
 * Created by AdminJia on 2016/11/26.
 */

public class GiftTuiJianPresenter {
    private IGiftTuiJianBiz iGiftTuiJianBiz;
    private IGiftTuiJianView iGiftTuiJianView;
    private Context context;


    public GiftTuiJianAdapter getAdapter() {
        return adapter;
    }

    private GiftTuiJianAdapter adapter = null;
    private List<GiftTuiJianBean.DataBean.ItemsBean> list_all;

    //private List<GiftTuiJianBean.DataBean.ItemsBean> items;
    public GiftTuiJianPresenter(IGiftTuiJianView iGiftTuiJianView, Context context) {
        this.iGiftTuiJianBiz = new GiftTuiJianBiz();
        this.iGiftTuiJianView = iGiftTuiJianView;
        this.context = context;
    }


    public void loadData(int offset) {
        iGiftTuiJianBiz.loadTuiJianData(new OnGiftTuiJianGetDataListener() {
            @Override
            public void success(List<GiftTuiJianBean.DataBean.ItemsBean> items, String string) {
                list_all = items;
                adapter = new GiftTuiJianAdapter(list_all, context);
                iGiftTuiJianView.setAdapterSuccess(adapter);
                iGiftTuiJianView.setImage(string);

            }

            @Override
            public void failed(Throwable t) {
                iGiftTuiJianView.setAdapterFailed(t);

            }
        }, offset);
    }


    public void refrashData(int offset) {
        iGiftTuiJianBiz.loadTuiJianData(new OnGiftTuiJianGetDataListener() {
            @Override
            public void success(List<GiftTuiJianBean.DataBean.ItemsBean> items, String string) {
                adapter.reloadRecyclerView(items, true);
                //  iGiftTuiJianView.addheaderSuccess(string);
                iGiftTuiJianView.setImage(string);
            }

            @Override
            public void failed(Throwable t) {
                iGiftTuiJianView.setAdapterFailed(t);

            }
        }, offset);
    }

    public void loadMOreData(int offset) {
        iGiftTuiJianBiz.loadTuiJianData(new OnGiftTuiJianGetDataListener() {
            @Override
            public void success(List<GiftTuiJianBean.DataBean.ItemsBean> items, String header_url) {
                int size = adapter.getmList().size();
                adapter.addItems(items, size);

                int size1 = adapter.getmList().size();
                Log.i("TAG", "-----------------------success: " + size1);

            }

            @Override
            public void failed(Throwable t) {

            }
        }, offset);
    }

}
